package mq

import "fmt"

type Error struct {
	Code    int
	Message string
}

func NewError(code int, message string) error {
	return &Error{code, message}
}

func (e *Error) Error() string {
	return fmt.Sprintf("MessageQueueError: %d %s", e.Code, e.Message)
}

func (e *Error) GetCode() int {
	return e.Code
}

func (e *Error) GetMessage() string {
	return e.Message
}

const (
	CodeChannelError = iota
	CodeDeclareQueueError
	CodeDeclareExchangeError
	CodeQueueBindError
	CodePublishError
	CodeConsumeError
)

var (
	ErrChannel         = NewError(CodeChannelError, "消息队列打开通道失败")
	ErrDeclareQueue    = NewError(CodeDeclareQueueError, "消息队列声明失败")
	ErrDeclareExchange = NewError(CodeDeclareExchangeError, "交换机声明失败")
	ErrQueueBind       = NewError(CodeQueueBindError, "队列绑定队列失败")
	ErrPublish         = NewError(CodePublishError, "消息队列发布失败")
	ErrConsume         = NewError(CodeConsumeError, "消息队列消费声明失败")
)
